<?php
namespace App\Libs\Tools;

use Illuminate\Support\Facades\Input;

class DataTables{

    public static function convert_transform_to_datatables(array $transform){
        $result=array();
        $result['draw']=Input::get('draw');
        $result['recordsTotal']=$transform['meta']['pagination']['total'];
        $result['recordsFiltered']=$transform['meta']['pagination']['total'];
        $result['data']=$transform['data'];
        return $result;
    }

    public static function get_order_column_tag(){
        if(!Input::get('order')) {
            return null;
        }
        $order_array=Input::get('order')[0];
        $columns=Input::get('columns');
        $order_column_index=$order_array['column'];
        $order_column_type=$order_array['dir'];
        $order_column_tag=["order_column"=>$columns[$order_column_index]['data'],
            "order_type"=>$order_column_type];
        return $order_column_tag;
    }

    public static function get_page_length(){
        return Input::get('length');
    }
}

